package br.com.universidade.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import br.com.universidade.bean.Usuario;
import br.com.universidade.config.ConnectFactory;

public class UsuarioDao {
	public static Usuario efetuarLogin(String login, String senha) throws SQLException {
		Connection connection = ConnectFactory.getConexao();
		String sql = "select * from usuario where login='" + login
				+ "' and senha='" + senha + "'";
		try {
			java.sql.PreparedStatement stmt = connection.prepareStatement(sql);
			ResultSet rs = stmt.executeQuery(sql);
			Usuario usuario = null;
			while (rs.next()) {
				usuario = new Usuario(rs.getString("login"),
						rs.getString("senha"), rs.getString("nome"));
			}
			rs.close();
			return usuario;
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return null;
		}finally{
			connection.close();
		}
	}
}
